<?
require_once("cms/core/action/AbstractListAction.php");

class ListAction extends AbstractListAction {

    private $log;

    public function __construct() {
        $this->log =& LoggerManager::getLogger("ListAction");
    }

    public function activate(ActionConfig &$mapping, &$form, Request &$request, Response &$response) {

        $this->log->debug("Activating contacts");
        $c = new Criteria();
        $c->add(ContactPeer::CONTACT_ID, $form->getItems(), Criteria::IN);
        $c->add(ContactPeer::ACTIVE, true);
        try {
            ContactPeer::doUpdate($c);
            $this->messages->add(ActionMessage::GLOBAL_MESSAGE,
                new ActionMessage("list.success.activate", true));
	        if($request->getContext()->getInitParameter(_Core::CACHE)) {
	            // Get the cache
	            $cache = $request->getContext()->getCache();             
	            // Clear the page cache
	            $cache->clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG, array('page'));
	        }
        } catch(PropelException $e) {
            $this->errors->add(ActionMessage::GLOBAL_MESSAGE,
                new ActionMessage("list.error.activate", true));
            $this->log->error($e->getMessage());
        }

    }

    public function deactivate(ActionConfig &$mapping, &$form, Request &$request, Response &$response) {

        $this->log->debug("Deactivating contacts");
        $c = new Criteria();
        $c->add(ContactPeer::CONTACT_ID, $form->getItems(), Criteria::IN);
        $c->add(ContactPeer::ACTIVE, false);
        try {
            ContactPeer::doUpdate($c);
            $this->messages->add(ActionMessage::GLOBAL_MESSAGE,
                new ActionMessage("list.success.deactivate", true));
	        if($request->getContext()->getInitParameter(_Core::CACHE)) {
	            // Get the cache
	            $cache = $request->getContext()->getCache();             
	            // Clear the page cache
	            $cache->clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG, array('page'));
	        }
        } catch(PropelException $e) {
            $this->errors->add(ActionMessage::GLOBAL_MESSAGE,
                new ActionMessage("list.error.deactivate", true));
            $this->log->error($e->getMessage());
        }

    }

    public function delete(ActionConfig &$mapping, &$form, Request &$request, Response &$response) {

        $this->log->debug("Deleting contacts");
        $c = new Criteria();
        $c->add(ContactPeer::CONTACT_ID, $form->getItems(), Criteria::IN);
        try {
            ContactPeer::doDelete($c);
            $this->messages->add(ActionMessage::GLOBAL_MESSAGE,
                new ActionMessage("list.success.delete", true));
	        if($request->getContext()->getInitParameter(_Core::CACHE)) {
	            // Get the cache
	            $cache = $request->getContext()->getCache();             
	            // Clear the page cache
	            $cache->clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG, array('page'));
	        }
        } catch(PropelException $e) {
            $this->errors->add(ActionMessage::GLOBAL_MESSAGE,
                new ActionMessage("list.error.delete", true));
            $this->log->error($e->getMessage());
        }

    }

}
?>